package servlet;

import java.io.IOException;
import java.sql.SQLException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import DAO.GroundBookDao;
import VO.GroundBook;

public class ground_book extends HttpServlet {

	public ground_book() {
		super();
	}

	public void destroy() {
		super.destroy(); // Just puts "destroy" string in log
		// Put your code here
	}


	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		this.doPost(request, response);
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException{
		int n=0;
		GroundBook groundbook = new GroundBook();
		GroundBookDao groundbookdao = new GroundBookDao();
		String account=request.getParameter("account");
		String bookstatus ="已预约";

//		try {
//			n=groundbookdao.user_book(account,bookstatus);
//		}catch (SQLException e) {
//			// TODO Auto-generated catch block
//			e.printStackTrace();
//		}
		
		
		
		if(n==1){
			String groundname = request.getParameter("ground");
			String date = request.getParameter("date");
			String time = request.getParameter("time");

			
			// String account = "0001";
			//  groundbook.setBid(bookid);
			groundbook.setGname(groundname);
			groundbook.setAccount(account);
			groundbook.setDay(date);
			groundbook.setTime(time);
			groundbook.setBstatus(bookstatus);
			  System.out.println("------"+groundbook);
			groundbookdao.saveGroundBook(groundbook);
			response.sendRedirect("/Gym/ground_book_successed.jsp");
		//	request.getRequestDispatcher("../ground_book_success.jsp").forward(request,response);

		}else if(n==0){
			response.sendRedirect("/Gym/fail.jsp");
			//request.getRequestDispatcher("../fail.jsp").forward(request,response);
		}

	}

	public void init() throws ServletException {
		// Put your code here
	}

}
